<?php
require_once '../../ptnhuan-web1/libraries/utilites/functions.php';
$path = "../../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating1 = NULL;
$rating2 = NULL;
?>
<form method="POST" align="center">
    <input type="text" name="rating1">
    <input type="text" name="rating2">
    <input type="submit" name="submit" value="Search">
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
    <?php $rating2 = (double) $_POST['rating2']; ?>
<?php endif; ?>
<?php
foreach ($films as $film):
    $mfil = explode(";", $film);
    $mfile = trim($mfil[0]);
    ?>
    <?php if (empty($rating1) && empty($rating2)): ?>
        <?php if (isset($mfil[1]) || isset($mfil[2])): ?>
            <img src = '../../ptnhuan-web1/public/images/films/<?php echo $mfile ?>'> 
            <?php echo $mfil[1] ?>
            <?php echo $mfil[2] ?>
            <br>
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($mfil[1]) || isset($mfil[2])): ?>
            <?php if (($rating1 <= (double) $mfil[2]) && ($rating2 >= (double) $mfil[2])): ?>
                <img src = '../../ptnhuan-web1/public/images/films/<?php echo $mfile ?>'> 
                <?php echo $mfil[1] ?>
                <?php if (!empty($mfil[2])) echo $mfil[2] ?>
                <br>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>           
<?php endforeach; ?>

            